package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.business.WorkReportMonthlyEnum;
import com.xbongbong.saas.enums.business.WorkReportPlanEnum;
import com.xbongbong.saas.enums.business.WorkReportTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/17 19:35
 * @since v1.0
 */
@Getter
public enum TempWorkReportMonthlyEnum {
    // 工作月报
    BASE_INFO(WorkReportMonthlyEnum.BASE_INFO),
    TYPE(WorkReportMonthlyEnum.TYPE),
    REPORT_DATE(WorkReportMonthlyEnum.REPORT_DATE),
    APPROVED_PEOPLE(WorkReportMonthlyEnum.APPROVED_PEOPLE),
    CC(WorkReportMonthlyEnum.CC),
    THIS_STATISTIC(WorkReportMonthlyEnum.THIS_STATISTIC),
    CONTENT(WorkReportMonthlyEnum.CONTENT),
    IMAGES(WorkReportMonthlyEnum.IMAGES),
    THIS_PLAN(WorkReportMonthlyEnum.THIS_PLAN),
    NEXT_PLAN(WorkReportMonthlyEnum.NEXT_PLAN),

    SYSTEM_INFO(WorkReportMonthlyEnum.SYSTEM_INFO),
    CREATOR_ID(WorkReportMonthlyEnum.CREATOR_ID),
    ADD_TIME(WorkReportMonthlyEnum.ADD_TIME),
    UPDATE_TIME(WorkReportMonthlyEnum.UPDATE_TIME),

    REVIEWER(WorkReportMonthlyEnum.REVIEWER),
    IS_RESSUE(WorkReportMonthlyEnum.IS_RESSUE),
    ;
    private WorkReportMonthlyEnum anEnum;

    TempWorkReportMonthlyEnum(WorkReportMonthlyEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempWorkReportMonthlyEnum> getAllEnum() {
        List<TempWorkReportMonthlyEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化报告类型
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initType(FieldAttrEntity fieldAttrEntity){
//        String str = "日报,周报,月报";
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setEditForbidden(0);
        fieldAttrEntity.setAdvancedSetHide(1);
        fieldAttrEntity.setVisibleScopeEnable(0);
        fieldAttrEntity.setEditableAdvanceEnable(0);
//        List<ItemPoJo> itemPoJoList = new ArrayList<>();
//        List<String> stringList = StringUtil.toStringList(str,",");
//        Integer value = 1;
//        for (String text : stringList){
//            ItemPoJo itemPoJo = new ItemPoJo();
//            itemPoJo.setText(text);
//            itemPoJo.setValue(value.toString());
//            if (value == 3) {
//                itemPoJo.setChecked(true);
//            } else {
//                itemPoJo.setChecked(false);
//            }
//            itemPoJoList.add(itemPoJo);
//            value++;
//        }
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(WorkReportTypeEnum.class,fieldAttrEntity.getFieldType(),null,"type");
        for (ItemPoJo itemPoJo : itemPoJoList){
            if (Objects.equals(itemPoJo.getValue(),WorkReportTypeEnum.MONTHLY.getType().toString())){
                itemPoJo.setChecked(true);
            }
        }
        fieldAttrEntity.setItems(itemPoJoList);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化批阅人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initApprovedPeople(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setEditable(0);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultValue("所有上级主管");
        defaultAttrPoJo.setDefaultType("custom");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setForbiddenSettingList(Arrays.asList((ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()),ForbiddenSettingEnum.DISABLE_TYPE.getAlias()));
        fieldAttrEntity.setMemo("“批阅人”可在【管理中心-其他设置】中进行更改。");
    }

    /**
     * 初始化业绩数据
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initThisStatistic(FieldAttrEntity fieldAttrEntity){
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(StringConstant.CUSTOM);
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setEditable(0);
    }

    /**
     * 初始化报告时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initReportDate(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType("yyyy-MM");
        fieldAttrEntity.setIsForbidden(0);
    }


    /**
     * 初始化下约计划子表单
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initNextPlan(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField(WorkReportPlanEnum.CONTENT.getAttr(), WorkReportPlanEnum.CONTENT.getAlias(), WorkReportPlanEnum.CONTENT.getSaasAttr(), FieldTypeEnum.TEXTAREA.getType(), 4, ShowTypeEnum.EDIT_DETAIL.getCode(), 0, 1);
        FieldAttrEntity item1 = InitExplainsHelper.setField(WorkReportPlanEnum.ID.getAttr(), WorkReportPlanEnum.ID.getAlias(), WorkReportPlanEnum.ID.getSaasAttr(), FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.NONE.getCode(), 1, 0);
        item1.setVisible(0);
        items.add(item);
        items.add(item1);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    /**
     * 初始化本月计划子表单
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initThisPlan(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField(WorkReportPlanEnum.CONTENT.getAttr(), WorkReportPlanEnum.CONTENT.getAlias(), WorkReportPlanEnum.CONTENT.getSaasAttr(), FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.EDIT_DETAIL.getCode(), 0, 1);
        FieldAttrEntity item1 = InitExplainsHelper.setField(WorkReportPlanEnum.STATUS.getAttr(), WorkReportPlanEnum.STATUS.getAttr(), WorkReportPlanEnum.STATUS.getAttr(), FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.EDIT_DETAIL.getCode(), 1, 1);
        FieldAttrEntity item2 = InitExplainsHelper.setField(WorkReportPlanEnum.ID.getAttr(), WorkReportPlanEnum.ID.getAlias(), WorkReportPlanEnum.ID.getSaasAttr(), FieldTypeEnum.NUM.getType(), 4, ShowTypeEnum.NONE.getCode(), 1, 0);
        item1.setVisible(0);
        items.add(item);
        items.add(item1);
        items.add(item2);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        fieldAttrEntity.setIsForbidden(1);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initCc(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setForbiddenSettingList(Arrays.asList((ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()),ForbiddenSettingEnum.DISABLE_TYPE.getAlias()));
    }
}
